<!-- 
 * 新增成果
 * @author: 冯宇
 * @since: 2022-05-16
 * index.vue
-->
<template>
  <div class="edit-achieve-container detailsPageBox">
    <div class="detailsMain">
    <div class="need-title" style="border:none;padding-top: 0;">
      <div class="icon"></div>
      <div>成果基本信息</div>
    </div>

    <el-form :model="data.form" label-width="110px" :rules="data.formRule" ref="dom1">
      <el-form-item label="成果名称：" prop="resultTitle">
        <el-input v-model="data.form.resultTitle" placeholder="请输入成果名称" style="width: 36%"></el-input>
      </el-form-item>
      <el-form-item label="成果所属领域：">
        <ChooseIndustry width="36%" @changeIndustry="changeIndustry" :backInfo="data.domain"></ChooseIndustry>
      </el-form-item>
      <el-form-item label="成果类型：">
        <el-button @click="checkButton(typeIndex, data.typeSelectList)" v-for="(type, typeIndex) in data.typeSelectList"
          :key="type.keyName" :type="type.state ? 'primary' : ''" style="margin-bottom: 8px">{{
              type.keyName
          }}</el-button>
      </el-form-item>
      <el-form-item label="成果所在地：">
        <ChooseAddress width="36%" :showDetailAddress="true" :backInfo="data.address" @changeAddress="changeAddress"></ChooseAddress>
      </el-form-item>
      <el-form-item label="成果截止日期：" prop="resultExpirationDate">
        <el-date-picker v-model="data.form.resultExpirationDate" format="YYYY-MM-DD" value-format="YYYY-MM-DD" type="date"
          placeholder="请选择截止日期" style="width: 36%" />
      </el-form-item>
      <el-form-item label="合作方式：">
        <el-button @click="checkButton(cooperationi, data.cooperationSelectList)"
          v-for="(cooperation, cooperationi) in data.cooperationSelectList" :key="cooperation.keyName"
          :type="cooperation.state ? 'primary' : ''"
          style="margin-bottom: 10px;margin-left: 0;margin-right: 10px;">{{ cooperation.keyName }}</el-button>
      </el-form-item>
      <el-form-item label="合作金额：" prop="resultBudget">
        <div style="display:flex;width:36%">
          <el-input v-model="data.form.resultBudget" :disabled="data.form.resultBudget===0" placeholder="请输入合作金额" style="flex:1"/>
          <div style="font-size:12px;margin:0 10px">万元</div> 
          <el-checkbox @change="setCooperation" v-model="data.form.resultBudgetType" label="价格面议" border/>
        </div>
      </el-form-item>
      <el-form-item label="技术成熟度：">
        <el-select v-model="data.form.resultSkillStageCode" style="width: 36%">
          <el-option :label="mature.keyName" :value="mature.keyId" v-for="mature in data.matureSelectList"
            :key="mature.keyName" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否含专利：">
        <el-radio v-model="data.form.includePatent" :label="true">包含专利技术</el-radio>
        <el-radio v-model="data.form.includePatent" :label="false">不包含专利技术</el-radio>
      </el-form-item>
      <el-form-item label="专利查询：">
        <div style="display:flex;width: 36%;">
          <el-input v-model="data.patentSearch" placeholder="请输入查询专利号"
          style="flex: 1;margin-right:10px"></el-input>
        <el-button type="primary" icon="Search" @click="searchPatent">查询专利</el-button>
        </div>
      </el-form-item>
      <el-form-item v-for="(patent,panIndex) in data.patentList" :key="'patent'+panIndex">
        <template #label>
          <div>
            <div>专利名称：</div>
            <div>专利号：</div>
            <div>专利介绍：</div>
          </div>
        </template>
        <template #default>
          <div>
            <div class="patent-name">{{ patent.ttl }}<el-button @click="data.patentList.splice(panIndex,1)" size="small" type="danger" style="margin-left:10px">删除</el-button></div>
            <div>{{ patent.pn }}</div>
            <div>{{ patent.abst }}</div>
          </div>
        </template>
      </el-form-item>
      <el-form-item label="成果描述：" prop="resultDescribe">
                          <!-- <div class="desc-container">
            <div class="container">
              <div class="title">示例选择</div>
              <el-select style="width: 100px" size="small" @change="changeExample" placeholder="示例列表">
                <el-option :label="example.sampleName" :value="example.sampleContent" v-for="(example,i) in data.descExampleSelectList" :key="'example'+i"/>
              </el-select>
            </div>
            <TextEditor @textEdit="textEdit" :type="0" :html="data.form.resultDescribe"></TextEditor>
          </div> -->
          <el-input v-model="data.form.resultDescribe" maxlength="2000" show-word-limit	 resize="none" rows="6" type="textarea"
            :placeholder="data.textAreaPlaceholder.p1" />
      </el-form-item>
      <el-form-item label="技术指标：">
        <!-- <TextEditor @textEdit="textEdit" :type="1" :html="data.form.resultTarget"></TextEditor> -->
        <el-input v-model="data.form.resultTarget" resize="none"  maxlength="2000" show-word-limit	 rows="6" type="textarea"
            :placeholder="data.textAreaPlaceholder.p2" />
      </el-form-item>
      <el-form-item label="应用案例：">
        <!-- <TextEditor @textEdit="textEdit" :type="2" :html="data.form.resultCase"></TextEditor> -->
        <el-input v-model="data.form.resultCase" resize="none"  maxlength="2000" show-word-limit	 rows="6" type="textarea"
            :placeholder="data.textAreaPlaceholder.p3" />
      </el-form-item>
      <el-form-item>
        <div>
          <div>
            <el-button type="primary" @click="textToKeywords">一键生成关键词和产业链</el-button>
          </div>
          <div class="form-item-template">
            <div class="form-item-title">成果关键词：</div>
            <div>
              <el-tag closable class="tag" v-for="(tag1, tag1index) in data.form.resultKeyword" :key="tag1"
                @close="closeTag(0, tag1index)">{{ tag1 }}</el-tag>
              <el-button type="success" @click="addKeyword">+添加成果关键词</el-button>
            </div>
          </div>
          <div class="form-item-template">
            <div class="form-item-title">成果产业链节点：</div>
            <div>
              <el-tag closable class="tag" v-for="(tag2, tag2index) in data.form.resultProductName" :key="tag2"
                @close="closeTag(1, tag2index)">{{ tag2 }}</el-tag>
            </div>
          </div>
        </div>
      </el-form-item>
    </el-form>

    <div class="need-title" style="border-bottom: none; margin-bottom: 0">
      <div class="icon"></div>
      <div>成果材料上传</div>
      <span class="tips">(上传相关材料有助于提高成果的可信度，增加匹配成功的几率)</span>
    </div>
    <div>材料建议：技术检测报告、样品图片、小试报告、中试报告、合作合同等直接证明技术成熟可行的材料</div>

    <el-form :model="form" label-width="110px" style="margin-top: 20px">
      <el-form-item label="添加图片" prop="achieveName">
        <div>
            <span class="tips">(最大5M，最多5张图片)</span>
            <el-upload list-type="picture-card" :file-list="data.imageList" :auto-upload="false" :on-preview="handlePictureCardPreview" :before-remove="beforeRemove" :on-remove="removeFile"
              :on-change="checkImage"  :limit="5" :multiple="true" style="margin-top:10px">
              <el-icon>
                <Plus />
              </el-icon>
            </el-upload>
            <el-dialog v-model="data.dialogVisible">
              <img w-full :src="data.dialogImageUrl" alt="预览" />
            </el-dialog>
        </div>
      </el-form-item>

      <el-form-item label="附件上传" prop="achieveName">
        <div class="upload-file-container">
            <span class="tips">(最大50M，文件格式Word、Excel、PDF，最多上传5个)</span>
          <el-upload :file-list="data.fileList"
            class="upload-demo"
            :auto-upload="false"
            :on-change="checkFile"
            :before-remove="beforeRemove"
            :on-remove="removeFile"
            :limit="5"
            :multiple="true"
            :on-preview="clickFile"
          >
            <el-button type="primary">请选择文件</el-button>
          </el-upload>
        </div>
      </el-form-item>
    </el-form>

    <div class="need-title">
      <div class="icon"></div>
      <div>成果联系人信息</div>
    </div>

    <el-form :model="data.form" label-width="110px" :rules="data.formRule" ref="dom2">
      <el-form-item label="姓名：" prop="resultContactPerson">
        <el-input v-model="data.form.resultContactPerson" style="width: 36%" />
      </el-form-item>
      <el-form-item label="手机：" prop="resultContactPhone">
        <el-input v-model="data.form.resultContactPhone" style="width: 36%" />
      </el-form-item>
    </el-form>

    <div class="need-title">
      <div class="icon"></div>
      <div>成果发布设置</div>
    </div>

    <el-form :model="data.form" label-width="110px">
      <el-form-item label="是否热门：">
        <el-radio-group v-model="data.form.isHot">
          <el-radio :label="true">是</el-radio>
          <el-radio :label="false">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="公开发布：">
        <el-checkbox v-model="data.form.isPublic">勾选后，成果会被更多用户看到，对接概率更大；不勾选则仅平台工作人员可见，保护您的隐私</el-checkbox>
      </el-form-item>
    </el-form>

    </div>
    <div class="send-btn detailsHandBtn">
      <el-button type="primary" style="width:100px;height:36px" @click="save">提交</el-button>
      <el-button style="width:100px;height:36px">重置</el-button>
    </div>


    <!-- 关键词弹出框 -->
    <el-dialog v-model="data.keywordsDialog" width="800px" :show-close="false" :close-on-click-modal="false">
      <template #title>
        <div class="dialog-title">
          <h2>成果关键词选择</h2>
          <div>系统根据您的成果描述，自动匹配了以下关键词，请选择合适的关键词哦~</div>
        </div>
      </template>
      <template #default>
        <el-checkbox-group v-model="data.form.keywords" @change="chooseKeywords" style="display:flex">
          <el-checkbox :label="keyword" border v-for="keyword in data.keywordsList" />
        </el-checkbox-group>
      </template>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="textToIndustry" :disabled="data.loading">下一步</el-button>
          <el-button @click="closeDialog(0)" :disabled="data.loading">取消</el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 产业链弹出框 -->
    <el-dialog v-model="data.industryDialog" width="800px" :show-close="false" :close-on-click-modal="false">
      <template #title>
        <div class="dialog-title">
          <h2>产业链节点选择</h2>
          <div>系统根据您的成果描述，自动匹配了以下节点，请选择合适的产业链节点哦~</div>
        </div>
      </template>
      <template #default>
        <el-checkbox-group v-model="data.form.industry" @change="chooseIndustry">
          <el-checkbox :label="industry.name" border v-for="industry in data.industryList" >
            {{ industry.name }}
                <el-tooltip class="item" effect="dark" :content="industry.describe" placement="right">
                  <el-icon><QuestionFilled /></el-icon>
                </el-tooltip>
          </el-checkbox>
        </el-checkbox-group>
      </template>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="data.industryDialog = false">确定添加</el-button>
          <el-button @click="closeDialog(1)">取消</el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 专利查询结果 -->
    <el-dialog v-model="data.patentDialog" width="40%" title="专利查询结果">
      <template #default>
        <div class="patent-search-result">
          <div>
            <span class="result-title">专利名称：</span><span class="result-text">{{ data.patentInfo.ttl }}</span>
          </div>
          <div class="result-middle">
            <span class="result-title">专利号：</span><span class="result-text">{{ data.patentInfo.pn }}</span>
          </div>
          <div>
            <span class="result-title">专利介绍：</span><span class="result-text">{{ data.patentInfo.abst }}</span>
          </div>
        </div>
      </template>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="addPatent">添加</el-button>
          <el-button @click="data.patentDialog = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
    <LoadingAnimation v-show="data.loading"></LoadingAnimation>
  </div>
</template>

<script setup>
import { onMounted, reactive, onUnmounted , ref } from 'vue'
import { getDictListApi, getDictItemListApi } from '@/api/public/publicDict.js'
import { textToKeywordsApi, textToIndustryApi } from '@/api/interface/algorithm.js' //算法
import { searchPatentApi } from '@/api/interface/patent.js'
import {getFileFlowByIdApi , delFileApi} from '@/api/interface/policy.js'
import { getExampleExplainTitleListApi, getExampleExplainListApi, allExampleApi } from '@/api/interface/exampleExplain.js'

import { achievementDetailApi,editAchievementApi } from '@/api/interface/achievement.js'
import { ElMessage, ElMessageBox } from 'element-plus'

import {backRoute,fileDownload} from '@/utils/common.js'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
const store = useStore()
const router = useRouter()
const route = useRoute()

const dom1 = ref(null)
const dom2 = ref(null)


onMounted(() => {
  const level = router.currentRoute.value.meta.level
  store.dispatch('setting/setRouterCut', level)
})
onUnmounted(() => {
  store.dispatch('setting/setRouterCut', 2)
})

const data = reactive({
  dialogVisible: false,
  dialogImageUrl: '',
  imageList: [],
  fileList:[],
  form: {},
  domain:{
    industryCode1: '',
    industryCode2: '',
    industryCode3: '',
    industryName1: '',
    industryName2: '',
    industryName3: '',
  },
  address:{
    provinceCode: null,
    cityCode: null,
    areaCode: null,
    provinceName: '',
    cityName: '',
    areaName:'',
    detailAddress: '',
  },
  formRule: {
    resultTitle: {
      required: true,
      validator: (rule, value, callback) => {
        if (/^[\u4e00-\u9fa5/a-zA-Z0-9-_#@&+=]{3,30}$/.test(value) == false) {
          callback(new Error('请输入3-30位字符，可使用特殊符号 _ # @ & + ='))
        } else {
          callback()
        }
      },
      trigger: 'blur',
    },
    resultExpirationDate: [
      { type: 'date', required: true, trigger: ['change', 'blur'], message: '请选择日期' },
      {
        validator: (rule, value, callback) => {
          if (new Date(value).getTime() < new Date().getTime()) {
            callback(new Error('请输入正确的时间'))
          } else {
            callback()
          }
        },
        trigger: 'change',
      },
    ],
    resultBudget: {
      required: true,
      validator: (rule, value, callback) => {
        if (/^[0-9]{1,12}$/.test(value) == false) {
          callback(new Error('请输入正确的金额，只能填写整数'))
        } else {
          callback()
        }
      },
      trigger: ['change', 'blur'],
    },
    resultDescribe: {
      required: true,
      validator: (rule, value, callback) => {
        if (value == '<p><br></p>') {
          callback(new Error('请填写成果描述'))
        } else {
          callback()
        }
      },
      trigger: ['blur', 'change', 'input'],
    },
    resultContactPerson: {
      required: true,
      validator: (rule, value, callback) => {
        if (/^[\u4e00-\u9fa5/0-9]{2,15}$/.test(value) == false) {
          callback(new Error('请输入正确的姓名'))
        } else {
          callback()
        }
      },
      trigger: 'blur',
    },
    resultContactPhone: {
      required: true,
      validator: (rule, value, callback) => {
        if (/^1[0-9]{10}$/.test(value) == false) {
          callback(new Error('请输入正确的手机号'))
        } else {
          callback()
        }
      },
      trigger: 'blur',
    },
  },
  textAreaPlaceholder: {
    p1: "",
    p2: "",
    p3: "",
  },
  patentSearch:'',
  patentInfo:{},
  patentDialog: false,
  patentList: [],
  typeSelectList: [],
  cooperationSelectList: [],
  matureSelectList: [],
  budgetSelectList: [],
  loading: false,
  keywordsDialog: false,
  industryDialog: false,
  keywordsList: [],
  industryList: [],
  descExampleSelectList: [],
})

//获取详细信息
const getAchievementDetail = ()=>{
  achievementDetailApi({id:route.params.id?route.params.id:sessionStorage.resultId}).then(res=>{
    if(res.status===200){
      data.form = res.data
      console.log(data.form,9999);
      res.data.resultBudgetType == 0 ? data.form.resultBudgetType = true : data.form.resultBudgetType = false
      console.log(data.form.resultBudgetType);
      data.patentList = res.data.patentList

      data.address.provinceCode = res.data.resultProvinceCode
      data.address.cityCode = res.data.resultCityCode
      data.address.areaCode = res.data.resultAreaCode
      data.address.provinceName = res.data.resultProvinceName
      data.address.cityName = res.data.resultCityName
      data.address.areaName = res.data.resultAreaName

      data.address.detailAddress = res.data.detailAddress

      data.domain.industryCode1 = res.data.industryCodeOne
      data.domain.industryCode2 = res.data.industryCodeTwo
      data.domain.industryCode3 = res.data.industryCodeThree
      data.domain.industryName1 = res.data.industryNameOne
      data.domain.industryName2 = res.data.industryNameTwo
      data.domain.industryName3 = res.data.industryNameThree

      res.data.file.forEach(v => {
        v.name = v.fileShowname
        if (v.fileSuffix !== 'jpg' && v.fileSuffix !== 'jpeg' && v.fileSuffix !== 'gif' && v.fileSuffix !== 'png' && v.fileSuffix !== 'webp') {
          data.fileList.push(v)
        } else {
          v.url = v.path
          data.imageList.push(v)
        }
      })
    }
  })
}
getAchievementDetail()


//查询专利
const searchPatent = () => {
  searchPatentApi({ pn: data.patentSearch }).then(res => {
    if (res.status === 200) {
      data.patentInfo = res.data.plist[0]
      data.patentDialog = true
    }
  })
}
//添加专利
const addPatent = () => {
  if (!data.patentList.find(v => v.pn == data.patentInfo.pn)) {
    data.patentList.push(data.patentInfo)
    data.patentSearch = ''
    data.patentDialog = false
  }else{
    data.patentDialog = false
    return
  }
}


//选择类型
const checkButton = (i, list) => {
  list.forEach((v) => {
    v.state = false
  })
  list[i].state = true
}
//价格面议
const setCooperation = (bool) => {
  if (bool) {
    data.form.resultBudget = 0
  } else {
    data.form.resultBudget = ''
  }
}
//富文本
const textEdit = (text, type) => {
  if (type === 0) {
    data.form.resultDescribe = text
  } else if (type === 1) {
    data.form.resultTarget = text
  } else if (type === 2) {
    data.form.resultCase = text
  }
}


//获取示例
const getExampleExplainList = async () => {
  allExampleApi().then(res => {
    if (res.status === 200) {
      res.data.forEach((v) => {
            if (v.sampleName == "成果描述") {
              data.textAreaPlaceholder.p1 = v.sampleContent
            } else if (v.sampleName == "技术指标") {
              data.textAreaPlaceholder.p2 = v.sampleContent
            } else if (v.sampleName == "应用案例") {
              data.textAreaPlaceholder.p3 = v.sampleContent
            }
          })
    }
  })
  // const pid = await getExampleExplainTitleListApi({
  //   sampleTitle: '',
  //   ipi: 1,
  //   ips: 20,
  // }).then((res) => {
  //   if (res.status === 200) {
  //     return res.data.result.find(v => v.sampleTitle == '成果描述').id
  //   }
  // })
  // console.log(pid);
  // getExampleExplainListApi({
  //   sampleTitleId: pid,
  //   ipi: 1,
  //   ips: 20,
  // }).then(res => {
  //   data.descExampleSelectList= res.data.result
  // })
}
getExampleExplainList()
// //选择示例
// const changeExample = (val) => {
//   data.form.resultDescribe = val
// }





//获取地址
const changeAddress = (info) => {
  data.address = info
}
//获取领域
const changeIndustry = (info) => {
  data.domain = info
}





//获取字典及字典项 / 成果类型  /  技术成熟度  / 合作方式  
const getDictList = async () => {
  const dict = {
    ipi: 1,
    ips: 20,
    keyName: '',
  }
  const dictList = await getDictListApi(dict).then((res) => {
    if (res.status === 200) {
      return res.data.result
    }
  })
  dictList.forEach((v) => {
    if (v.keyId === 'DICT_RESULT_COOPERATION') {
      let a = {
        dictType: v.keyId,
        ipi: 1,
        ips: 10,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {//合作方式
        data.cooperationSelectList = res.data.result.map((v) => {
          if(v.keyName===data.form.resultCooperationName){
            v.state = true
          }else{
            v.state = false
          }
          return v
        })
        // data.cooperationSelectList[0].state = true
      })
    } else if (v.keyId === 'DICT_RESULT') {
      let a = {
        dictType: v.keyId,
        ipi: 1,
        ips: 10,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {//成果类型
        data.typeSelectList = res.data.result.map((v) => {
          if(v.keyName===data.form.resultTypeName){
            v.state = true
          }else{
            v.state = false
          }
          return v
        })
        // data.typeSelectList[0].state = true
      })
    } else if (v.keyId === 'DICT_SKILL_STAGE') {
      let a = {
        dictType: v.keyId,
        ipi: 1,
        ips: 10,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {//成熟度
        data.matureSelectList = res.data.result
        data.form.resultSkillStageCode = data.matureSelectList.find(v=> v.keyName==data.form.resultSkillStageName).keyId
      })
    }
  })
}
getDictList()




//文本内容获取关键词
const textToKeywords = () => {
  data.loading = true
  const params = {
    data: data.form.resultDescribe+data.form.resultTarget+data.form.resultCase,
    n: 20,
  }
  textToKeywordsApi(JSON.stringify(params)).then((res) => {
    if (res.status === 200) {
      data.keywordsList = res.data.keyword
      data.keywordsDialog = true
    }
    data.loading = false
  })
}
//文本内容获取产业链节点
const textToIndustry = () => {
  data.loading = true
  const params = {
    data: data.form.resultDescribe+data.form.resultTarget+data.form.resultCase,
    n: 20,
  }
  textToIndustryApi(JSON.stringify(params)).then((res) => {
    if (res.status === 200) {
      data.keywordsDialog = false
      data.industryList = res.data.industry_node
      data.industryDialog = true
    }
    data.loading = false
  })
}
//选择关键词
const chooseKeywords = (words) => {
  data.form.resultKeyword = words
}
//选择产业链
const chooseIndustry = (words) => {
  data.form.resultProductName = words
}
//取消
const closeDialog = (type)=>{
  if(type===0){
    data.form.resultKeyword=[]
      data.keywordsDialog= false
  }else if(type===1){
    data.industryDialog=false
    data.form.resultProductName= []
  }
}
//手动添加关键词
const addKeyword = () => {
  ElMessageBox.prompt('请输入成果关键词', '', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    inputPattern: /^[\u4e00-\u9fa5/a-zA-Z0-9]{1,15}$/,
    inputErrorMessage: '请输入正确的关键词'
  })
    .then(({ value }) => {
      data.form.resultKeyword.push(value)
    })
}
//删除关键词或产业链
const closeTag = (type, i) => {
  if (type === 0) {
    data.form.resultKeyword.splice(i, 1)
  } else if (type === 1) {
    data.form.resultProductName.splice(i, 1)
  }
}



//图片校验
const checkImage = (file, files) => {
  const name = file.raw.name.slice(file.raw.name.lastIndexOf('.')+1)
  if (name !== 'jpeg' && name !== 'jpg' && name !== 'webp' && name !== 'png' && name !== 'gif') {
    files.forEach((v, i) => {
      if (v.name === file.name) {
        files.splice(i, 1)
      }
    })
    ElMessage.error('图片格式不正确')
  }
  if (file.raw.size / 1024 / 1024 > 5) {
    files.forEach((v, i) => {
      if (v.name === file.name) {
        files.splice(i, 1)
      }
    })
    ElMessage.error('每张图片大小不超过5M')
  }
}
//图片预览
const handlePictureCardPreview = (uploadFile) => {
  data.dialogImageUrl = uploadFile.url
  data.dialogVisible = true
}
//选择文件
const checkFile = (file, files) => {
  const name = file.raw.name.slice(file.raw.name.lastIndexOf('.')+1)
  if (name !== 'doc' && name !== 'docx' && name !== 'xls' && name !== 'xlsx' && name !== 'pdf') {
    files.forEach((v, i) => {
      if (v.name === file.name) {
        files.splice(i, 1)
      }
    })
    ElMessage.error('请上传指定格式的文件')
  }
  if (file.raw.size / 1024 / 1024 > 50) {
    files.forEach((v, i) => {
      if (v.name === file.name) {
        files.splice(i, 1)
      }
    })
    ElMessage.error('文件大小不超过50M')
  }
}
//删除提示
const beforeRemove = (uploadFile, uploadFiles) => {
  return ElMessageBox.confirm(
    `该操作将永久删除该文件，是否确定？`
  ).then(
    () => true,
    () => false
  )
}
//删除文件
const removeFile = (file, files) => {
  let id = file.id ?? null
  if (id) {
    delFileApi({ fileId: id, bucket: file.bucket }).then(res => {
      if (res.status === 200) {
        console.log(res);
      }
    })
  }
}
//下载文件
const clickFile = (file) => {
    const params = {
    fileId: file.id
  }
  getFileFlowByIdApi(params).then(res => {
    fileDownload(file, res)
  })
}





//保存编辑
const save = async() => {
  let a = await dom1.value.validate(bool=> bool)
  let b = await dom2.value.validate(bool => bool)
  if(!a||!b) return
  const params = {
    id:data.form.id,
    resultTitle: data.form.resultTitle,
    industryNameOne: data.domain.industryName1,
    industryCodeOne: data.domain.industryCode1,
    industryNameTwo: data.domain.industryName2,
    industryCodeTwo: data.domain.industryCode2,
    industryNameThree: data.domain.industryName3,
    industryCodeThree: data.domain.industryCode3,
    resultTypeName: data.typeSelectList.find((v) => v.state).keyName,
    resultTypeCode: data.typeSelectList.find((v) => v.state).keyId,
    resultProvinceName: data.address.provinceName,
    resultProvinceCode: data.address.provinceCode,
    resultCityName: data.address.cityName,
    resultCityCode: data.address.cityCode,
    resultAreaName: data.address.areaName,
    resultAreaCode: data.address.areaCode,
    detailAddress:data.address.detailAddress,
    resultExpirationDate: data.form.resultExpirationDate,
    resultCooperationName: data.cooperationSelectList.find((v) => v.state).keyName,
    resultCooperationCode: data.cooperationSelectList.find(v => v.state).keyId,
    resultBudgetType: data.form.resultBudgetType ? '0' : '1',
    resultBudget: data.form.resultBudget,
    resultSkillStageName: data.matureSelectList.find(v => v.keyId == data.form.resultSkillStageCode).keyName,
    resultSkillStageCode: data.form.resultSkillStageCode,
    includePatent: data.form.includePatent,
    patentList: data.patentList.map(v=> v.pn),//专利号列表
    resultDescribe: data.form.resultDescribe,
    resultTarget: data.form.resultTarget,
    resultCase: data.form.resultCase,
    resultKeyword: data.form.resultKeyword,
    resultProductName: data.form.resultProductName,
    resultContactPerson: data.form.resultContactPerson,
    resultContactPhone: data.form.resultContactPhone,
    isHot: data.form.isHot,
    isPublic: data.form.isPublic,
  }
  const newFileArr = [...data.imageList, ...data.fileList].filter(v => !v.id)
  let fd = new FormData()
  fd.append('form',new Blob([JSON.stringify(params)]))
  if (newFileArr.length > 0) {
    newFileArr.forEach(v => {
      fd.append('file',v.raw)
    })
  }
  editAchievementApi(fd).then(res => {
    if (res.status === 200) {
      ElMessage({
        message: res.message,
        type: 'success',
      })
        backRoute('Achievement')
    }
  })
}

</script>

<style lang="scss" scoped>
.el-select-dropdown__list {
  .el-select-dropdown__item {
    font-size: 12px;
  }
}
.edit-achieve-container {
  padding: 20px;
    ::v-deep .el-radio__label{
    font-size: 12px;
  }
  :deep(.el-textarea__inner){
    margin-top: 10px;
    padding: 10px;
  }
  ::v-deep .el-checkbox__label{
    font-size: 12px;
  }
    .patent-search-result {
    .result-middle {
      margin: 6px 0;
    }

    .result-title {
      font-weight: 700;
      font-size: 12px;
      color: #00a2ff;
    }

    .result-text {
      font-size: 12px;
      line-height: 24px;
    }
  }
  .patent-name {
    color: #00a2ff;
    font-weight: 700;
  }

  .form-item-template {
    display: flex;
    align-items: center;
    margin-top: 20px;
  }

  .tag {
    height: 32px;
    line-height: 32px;
    margin-right: 10px;
  }

  .tips {
    color: #f74b33;
    font-size: 14px;
    margin-left: 10px;
  }

  ::v-deep .el-form-item__label {
    font-weight: 700;
  }
  .upload-file-container{
    width: 50%;
    max-width: 600px;
  }
  .need-title {
    display: flex;
    align-items: center;
    padding: 20px 0;
    font-size: 16px;
    font-weight: 700;
    border-top: 1px solid #e3e3e3;

    .icon {
      width: 6px;
      height: 16px;
      background: #00a2ff;
      margin-right: 10px;
    }
  }

  .send-btn {
    text-align: center;
  }
    .el-dialog__body {
    img {
      width: 100%;
    }
  }
}
.desc-container {
  position: relative;
  width: 100%;

  .container {
    position: absolute;
    left: -110px;
    top: 40px;

    .title {
      font-weight: 700;
      color: #00a2ff;
      font-size: 12px;
      height: 14px;
      line-height: 14px;
    }
  }

  ::v-deep .el-input__inner {
    box-shadow: 0 0 0 1px #c0c4cc inset;
  }
}
:deep(.el-dialog__header) {
    color: #333;
    line-height: 20px;
    padding: 20px 20px 0 20px;

    h2 {
      margin-bottom: 10px;
    }
}

:deep(.el-dialog__body) {
    padding: 20px;
    padding-bottom: 10px;

    .el-checkbox-group {
      flex-wrap: wrap;
      line-height: 30px;

      .el-checkbox {
        width: 130px;
        margin: 0;
        margin-right: 22px;
        margin-bottom: 10px;
      }
    }

    .el-icon-question {
      color: #C5C9DB;
      transition: all 0.6s;

      &:hover {
        color: #F0454D;
      }
    }
}
</style>